package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BizMonthlyExpenses;
import com.ruoyi.system.service.IBizMonthlyExpensesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月度开销Controller
 * 
 * @author luoshuai
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/system/expenses")
public class BizMonthlyExpensesController extends BaseController
{
    @Autowired
    private IBizMonthlyExpensesService bizMonthlyExpensesService;

    /**
     * 查询月度开销列表
     */
    @PreAuthorize("@ss.hasPermi('system:expenses:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizMonthlyExpenses bizMonthlyExpenses)
    {
        startPage();
        List<BizMonthlyExpenses> list = bizMonthlyExpensesService.selectBizMonthlyExpensesList(bizMonthlyExpenses);
        return getDataTable(list);
    }

    /**
     * 导出月度开销列表
     */
    @PreAuthorize("@ss.hasPermi('system:expenses:export')")
    @Log(title = "月度开销", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizMonthlyExpenses bizMonthlyExpenses)
    {
        List<BizMonthlyExpenses> list = bizMonthlyExpensesService.selectBizMonthlyExpensesList(bizMonthlyExpenses);
        ExcelUtil<BizMonthlyExpenses> util = new ExcelUtil<BizMonthlyExpenses>(BizMonthlyExpenses.class);
        util.exportExcel(response, list, "月度开销数据");
    }

    /**
     * 获取月度开销详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:expenses:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(bizMonthlyExpensesService.selectBizMonthlyExpensesByOrderId(orderId));
    }

    /**
     * 新增月度开销
     */
    @PreAuthorize("@ss.hasPermi('system:expenses:add')")
    @Log(title = "月度开销", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizMonthlyExpenses bizMonthlyExpenses)
    {
        return toAjax(bizMonthlyExpensesService.insertBizMonthlyExpenses(bizMonthlyExpenses));
    }

    /**
     * 修改月度开销
     */
    @PreAuthorize("@ss.hasPermi('system:expenses:edit')")
    @Log(title = "月度开销", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizMonthlyExpenses bizMonthlyExpenses)
    {
        return toAjax(bizMonthlyExpensesService.updateBizMonthlyExpenses(bizMonthlyExpenses));
    }

    /**
     * 删除月度开销
     */
    @PreAuthorize("@ss.hasPermi('system:expenses:remove')")
    @Log(title = "月度开销", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(bizMonthlyExpensesService.deleteBizMonthlyExpensesByOrderIds(orderIds));
    }
}
